package com.momoda.monitor.bean;

import lombok.Data;
import org.apache.commons.codec.digest.DigestUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

@Data
public class FileInfo {

    /**
     * 发送变化的文件路径
     */
    public String path;
    /**
     * 发送变化时间
     */
    public String time;
    /**
     * 文件hash值
     */
    public String hash;
    /**
     * 1为存在
     */
    public String exist = "1";


    public FileInfo() {
    }

    public FileInfo(String path, String time) {
        this.path = path;
        this.time = time;
    }

    public FileInfo(String path, String time, String exist) {
        this.path = path;
        this.time = time;
        this.exist = exist;
        try {
            this.hash = DigestUtils.md5Hex(new FileInputStream(new File(path)));
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    public FileInfo(String path, String time, String hash, String exist) {
        this.path = path;
        this.time = time;
        this.hash = hash;
        this.exist = exist;
    }


}
